<?php
/**
 * Description: 各订单数量
 *
 * @author      Eden
 * @datetime    2017/1/11 21:17
 * @copyright   WuHan HuQi Technology Co.,Ltd.
 * @url         http://cnhuqi.com
 */

class Num_Model extends API_Model
{
    /**
     * 初始化
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 主程序
     * @param $params
     */
    public function run($params)
    {

        $send['state'] = false;
        do {

            if (empty($params['userId'])) {
                $send['error'] = '参数错误';
                break;
            }

            $status = [
                'Unpaid' => 0,
                'Pending' => 0,
                'Dispatch' => 0,
                'Complete' => 0,
                'Cancel' => 0,
                'Refund' => 0,
                'Refunded' => 0
            ];

            $db = clone($this->db);
            $q = $db->get_where('user_order', [
                'userId' => $params['userId']
            ]);
            $rows = $q->result_array();
            if (!empty($rows)) foreach($rows as $row) {
                $state = $row['status'];
                $status[$state] += 1;
            }

            $send['state'] = true;
            $send['data'] = $status;

        } while(false);
        $this->output->send($send);
    }
}

